package spring.JUNIT.aop;

import java.lang.reflect.Method;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

public class zzyAspect {

	public void before() {
		System.out.println("zzyAop before");
	}

	public void afterReturning() {
		System.out.println("zzyAop afterReturning");

	}

	public void afterThrowing() {
		System.out.println("zzyAop afterThrowing--自动手动回滚");
	}

	public void after() {
		System.out.println("zzyAop after");
	}

	public Object around(ProceedingJoinPoint pjp) throws Throwable {// 通知内处理异常
																	// 还是抛出
		System.out.println("aspect around 1--开启手动提交");
		Object obj = pjp.proceed();
		// 获取当前方法
		Signature sig = pjp.getSignature();
		MethodSignature msig = null;
		if (!(sig instanceof MethodSignature)) {
			throw new IllegalArgumentException("该注解只能用于方法");
		}
		msig = (MethodSignature) sig;
		Object target = pjp.getTarget();
		Method currentMethod = target.getClass().getMethod(msig.getName(),
				msig.getParameterTypes());

		System.out.println(currentMethod);
		System.out.println("aspect around 2 --自动手动提交");

		return obj;

	}

	public Object aroundInit(ProceedingJoinPoint pjp, String bizName, int times)
			throws Throwable {// 通知内处理异常
		// 还是抛出

		System.out.println(bizName + "  " + times);
		System.out.println("aspect around 1--开启手动提交");
		Object obj = pjp.proceed();
		// 获取当前方法
		Signature sig = pjp.getSignature();
		MethodSignature msig = null;
		if (!(sig instanceof MethodSignature)) {
			throw new IllegalArgumentException("该注解只能用于方法");
		}
		msig = (MethodSignature) sig;
		Object target = pjp.getTarget();
		Method currentMethod = target.getClass().getMethod(msig.getName(),
				msig.getParameterTypes());

		System.out.println(currentMethod);
		System.out.println("aspect around 2 --自动手动提交");

		return obj;

	}
}
